home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.3d26 source
/
tn3270
/
serscrn.c
< prev
next >
Wrap
Text File
|
1991-02-15
|
13KB
|
563 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.3d21, January 17, 1991
* Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#define __SEG__ 3270seg3
#include "maclib.h"
#include "termdef.h"
#include "globals.h"
extern Rect textRect, gr_rect;
extern short maxoff, maxcnt;
extern PaletteHandle myPalette;
extern RGBColor realwhite;
extern short scrhsize, scrhoff;
extern char servermode, serverflags;
extern unsigned char tcphostname[]; /* cshostname, or prompt response */
char skiplf, escmode;
short msgoffset;
unsigned char *linetext;
unsigned short *lineattr;
short linelen;
unsigned char *proctext;
unsigned short *procattr;
unsigned char *prochost;
char respflag;
unsigned char cptoebc[] = {
0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f,
0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f,
0x10,0x11,0x12,0x3b,0x3c,0x3d,0x32,0x26,
0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f,
0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d,
0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61,
0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f,
0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,
0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,
0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6,
0xe7,0xe8,0xe9,0xad,0xe0,0xbd,0x5f,0x6d,
0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96,
0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6,
0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07};
putscr(s, slen, wr)
unsigned char *s;
short slen;
char wr;
{
static unsigned char idstr[] = {0x1b, 0x2f, 0x5a};
register unsigned char a, c;
register short count;
short i, m, newadr;
char writeflg;
unsigned char saverow;
if (slen == 0) return;
writeflg = 0;
newadr = curadr;
for (count=0; count < slen; count++) {
a = s[count];
if (wr) mout(a);
c = cptoebc[a & 0x7f];
switch(escmode) {
case 0: /* no preceding ESC */
if (c >= 0x40) skiplf = 0;
switch(c) {
case 0x2f: /* bell (07) */
pndbeep = 1;
break;
case 0x16: /* backspace (08) */
if (newadr == 0) newadr = maxoff;
else newadr--;
break;
case 0x05: /* horizontal tab (09) */
newadr >> 2;
newadr += 1;
newadr << 2;
if (newadr > maxoff) newadr = 0;
break;
case 0x25: /* line feed (0A) */
if (skiplf) {
skiplf = 0;
break;
}
newadr = (newadr/scrhsize) * scrhsize;
m = maxoff/scrhsize;
i = newadr/scrhsize;
if (i < m) newadr += scrhsize;
else {
scrollscrn();
writeflg = 0;
}
break;
case 0x0b: /* vertical tab (0B) */
newadr += scrhsize;
if (newadr > maxoff) newadr -= maxcnt;
break;
case 0x0c: /* form feed (0C) */
clrscn();
invldscr();
newadr = 0;
break;
case 0x0d: /* carriage return (0D) */
newadr = (newadr/scrhsize) * scrhsize;
break;
case 0x27: /* ESC */
escmode = 1;
default:
if (c < 0x40) break; /* ignore other control chars. */
/* data character */
if ((c == 0xad) || (c == 0xbd)) newchar(newadr, c, 0x4000, 0);
else newchar(newadr, c, 0, 0);
writeflg = 1;
newadr++;
if ((newadr%scrhsize) == 0) skiplf = 1;
if (newadr == maxcnt) {
newadr = (maxoff/scrhsize) * scrhsize;
scrollscrn();
writeflg = 0;
}
break;
}
break;
case 1: /* first char. after ESC */
switch(c) {
case 0xc1: /* A - up */
if ((newadr-scrhsize) >= 0) newadr -= scrhsize;
escmode = 0;
break;
case 0xc2: /* B - down */
if ((newadr+scrhsize) < maxcnt) newadr += scrhsize;
escmode = 0;
break;
case 0xc3: /* C - right */
if ((newadr+1) < maxcnt) newadr++;
escmode = 0;
break;
case 0xc4: /* D - left */
if ((newadr-1) >= 0) newadr--;
escmode = 0;
break;
case 0xc8: /* H - cursor home */
newadr = 0;
escmode = 0;
break;
case 0xc9: /* I - reverse line feed */
if (newadr > scrhoff) newadr -= scrhsize;
else {
revscroll();
writeflg = 0;
}
escmode = 0;
break;
case 0xd1: /* J - erase to end of screen */
i = newadr;
newchar(i, 0, 0, 0);
i++;
while (i < maxcnt) {
newchar(i, 0, 0, 0);
i++;
}
writeflg = 1;
escmode = 0;
break;
case 0xd2: /* K - erase to end of line */
i = newadr;
newchar(i, 0, 0, 0);
i++;
while ((i < maxcnt) && ((i%scrhsize) != 0)) {
newchar(i, 0, 0, 0);
i++;
}
writeflg = 1;
escmode = 0;
break;
case 0xe8: /* Y - start of cursor address */
escmode = 2;
break;
case 0xe9: /* Z - return my terminal type */
if (tcpflg) {
tcpwrite(idstr, 3);
}
else if (serflg) {
mout(idstr[0]);
mout(idstr[1]);
mout(idstr[2]);
}
escmode = 0;
break;
default:
escmode = 0;
break;
}
break;
case 2: /* second char. after ESC */
saverow = a;
escmode = 3;
break;
case 3: /* third char. after ESC */
newadr = (saverow - 0x20) * scrhsize + a - 0x20;
if (newadr < 0) newadr = 0;
if (newadr > maxoff) newadr = maxoff;
escmode = 0;
break;
default:
break;
}
}
if (writeflg) newwrite(0);
if (curadr != newadr) {
curadr = newadr;
newcur();
}
}
scrollscrn()
{
register short i, n;
unsigned char * cptr;
short * iptr;
/* update character and attribute buffers */
n = maxcnt/scrhsize - 1;
cptr = chrbuff;
iptr = atrbuff;
for (i=0; i < n; i++) {
movmem(cptr+scrhsize, cptr, scrhsize);
movmem(iptr+scrhsize, iptr, scrhsize<<1);
cptr += scrhsize;
iptr += scrhsize;
}
setmem(cptr, scrhsize, 0);
setmem(iptr, scrhsize<1, 0);
/* prevent drawing of saved input */
in_len = 0;
inrect.top = inrect.left = 32767;
inrect.bottom = inrect.right = -32767;
/* update bitmap or screen */
invldscr();
}
revscroll()
{
register short i, n;
unsigned char * cptr;
short * iptr;
/* update character and attribute buffers */
n = maxcnt/scrhsize - 1;
cptr = chrbuff + maxcnt - scrhsize;
iptr = atrbuff + maxcnt - scrhsize;
for (i=0; i < n; i++) {
movmem(cptr-scrhsize, cptr, scrhsize);
movmem(iptr-scrhsize, iptr, scrhsize<<1);
cptr -= scrhsize;
iptr -= scrhsize;
}
setmem(cptr, scrhsize, 0);
setmem(iptr, scrhsize<1, 0);
/* prevent drawing of saved input */
in_len = 0;
inrect.top = inrect.left = 32767;
inrect.bottom = inrect.right = -32767;
/* update bitmap or screen */
invldscr();
}
putsrv(s, slen, inp)
unsigned char *s;
short slen;
char inp;
{
register unsigned char a, c;
short count, i, len, m, newadr, startadr;
char writeflg;
unsigned char *cptr;
if (slen == 0) return;
writeflg = 0;
newadr = curadr;
startadr = maxcnt - scrhsize * 2;
for (count=0; count < slen; count++) {
a = s[count];
c = cptoebc[a & 0x7f];
if (!inp) {
srvnewchar(c);
continue;
}
switch(c) {
case 0x16: /* backspace (08) */
if (newadr == startadr) break;
newadr--;
newchar(newadr, 0, 0, 0);
writeflg = 1;
break;
case 0x0d: /* carriage return (0D) */
cptr = chrbuff + maxoff;
for (i = scrhsize*2; i > 0; i--) {
a = *(cptr--);
if ((a != 0) && (a != 0x40)) break;
}
len = i;
newadr = startadr;
if (len == 0) break;
if (serflg) {
respflag = 1;
cptr = chrbuff + startadr;
for (i = 0; i < len; i++) {
mout(((*xtabh)[cptr[i]]) & 0x7f);
}
mout(0x0d);
}
else {
srvtext(chrbuff + startadr, atrbuff + startadr, len);
cptr = chrbuff + startadr;
for (i = 0; i < len; i++) {
cptr[i] = (*xtabh)[cptr[i]];
}
cptr[len++] = 0x0d;
cptr[len++] = 0x0a;
tcpwrite(cptr, len);
}
setmem(chrbuff + startadr, scrhsize*2, 0);
setmem(atrbuff + startadr, scrhsize*4, 0);
/* prevent drawing of saved input */
in_len = 0;
inrect.top = inrect.left = 32767;
inrect.bottom = inrect.right = -32767;
/* update bitmap or screen */
invldscr();
break;
default:
if (c < 0x40) break; /* ignore other control chars. */
/* data character */
if (newadr == maxoff) {
beep();
break;
}
if ((c == 0xad) || (c == 0xbd)) newchar(newadr, c, 0x4006, 6);
else newchar(newadr, c, 6, 6);
writeflg = 1;
newadr++;
break;
}
}
if (writeflg) newwrite(0);
if (curadr != newadr) {
curadr = newadr;
newcur();
}
}
srvnewchar(c)
unsigned char c;
{
int rc;
switch(c) {
case 0x25:
rc = srvproc(linetext, lineattr, linelen);
if (rc == 0) srvtext(linetext, lineattr, linelen);
linelen = 0;
break;
default:
if (c < 0x40) break;
if (linelen == 512) break;
linetext[linelen] = c;
if ((c == 0xad) || (c == 0xbd)) lineattr[linelen++] = 0x4000;
else lineattr[linelen++] = 0;
break;
}
}
srvtext(text, attr, len)
unsigned char *text;
unsigned short *attr;
short len;
{
short i, linecount, scrollcount;
if (len == 0) return;
linecount = (len + scrhsize - 1)/scrhsize;
scrollcount = linecount - (maxcnt - scrhsize*2 - msgoffset)/scrhsize;
if (scrollcount > 0) {
for (i = 0; i < scrollcount; i++) {
srvscroll();
msgoffset -= scrhsize;
}
}
if (((attr[0] & 0x07) == 6) || respflag) {
for (i = 0; i < len; i++) {
attr[i] &= 0xFFF8;
attr[i] |= 5;
}
respflag = 0;
}
movmem(text, chrbuff+msgoffset, len);
movmem(attr, atrbuff+msgoffset, len<<1);
msgoffset += linecount*scrhsize;
/* prevent drawing of saved input */
in_len = 0;
inrect.top = inrect.left = 32767;
inrect.bottom = inrect.right = -32767;
/* update bitmap or screen */
invldscr();
}
int srvproc(text, attr, len)
unsigned char *text;
unsigned short *attr;
short len;
{
short i;
static char hostok = 0;
unsigned char *irchost;
short ircsize;
if (len == 0) return(0);
if (serverflags == 0) return(0);
movmem(text, proctext, len);
movmem(attr, procattr, len<<1);
/* IRC processing */
if (len < 5) return(0);
for (i = 0; i < 5; i++) {
proctext[i] = (*xtabh)[proctext[i]];
}
proctext[5] = 0;
if (strcmp(proctext, "PING ") == 0) {
if (hostok == 0) {
hostok = 1;
strcpy(prochost, "PONG ");
if (serflg) irchost = cshostname;
else irchost = tcphostname;
while ((*irchost != '\0') && (*irchost != ':')) irchost++;
ircsize = 0;
if (*irchost == ':') {
irchost++;
while ((irchost[ircsize] != '\0') &&
(irchost[ircsize] != ':')) ircsize++;
}
if (ircsize > 0) {
for (i=0; i < ircsize; i++) {
prochost[i+5] = tolower(irchost[i]);
}
prochost[ircsize+5] = 0;
}
else prochost[4] = 0;
i = strlen(prochost);
if (serflg) {
prochost[i] = 0x0d;
}
else {
prochost[i++] = 0x0d;
prochost[i] = 0x0a;
}
}
if (serflg) {
i = 0;
while (prochost[i] != 0) {
mout(prochost[i++]);
}
respflag = 1;
return(1);
}
else {
tcpwrite(prochost, strlen(prochost));
return(0);
}
}
return(0);
}
srvscroll()
{
register short i, n;
unsigned char * cptr;
short * iptr;
/* update character and attribute buffers */
n = maxcnt/scrhsize - 1;
n -= 2;
cptr = chrbuff;
iptr = atrbuff;
for (i=0; i < n; i++) {
movmem(cptr+scrhsize, cptr, scrhsize);
movmem(iptr+scrhsize, iptr, scrhsize<<1);
cptr += scrhsize;
iptr += scrhsize;
}
setmem(cptr, scrhsize, 0);
setmem(iptr, scrhsize<<1, 0);
}
srvswitch()
{
servermode ^= 1;
if (servermode) {
curadr = maxcnt - scrhsize*2;
msgoffset = 0;
linelen = 0;
linetext = readbuff;
lineattr = (unsigned short *)(linetext + 512);
proctext = linetext + 1536;
procattr = (unsigned short *)(linetext + 2048);
prochost = linetext + 3072;
respflag = 0;
}
else {
curadr = 0;
}
setmem(chrbuff, maxcnt, 0);
setmem(atrbuff, maxcnt<<1, 0);
/* prevent drawing of saved input */
in_len = 0;
inrect.top = inrect.left = 32767;
inrect.bottom = inrect.right = -32767;
/* update bitmap or screen */
invldscr();
newcur();
}